// 负责获取token的函数
import store from '../store/index'
export default async () => {
    let token = store.state.token
    if (token) return token
    const [err, { encryptedData, rawData, iv, signature }] = await uni.getUserProfile({
        desc: "用于给用户带来更好的体验",
    });
    const [err1, { code }] = await uni.login()
    const params = {
        encryptedData, rawData, iv, signature, code
    }
    // 发送请求，获取token
    const res = await uni.$u.http.post("/users/wxlogin", params)
    token = res.message.token
    store.commit('setToken', token)
    return token
}